package com.jcl.recruit.core.config;

import com.jcl.core.utils.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import java.util.Map;


/**
 * @ClassName EmailConfig

 * @Author yyliu
 * @Date 2018/9/17 13:18
 * @Version 1.0
 **/
@Component
public class TemplateConfig {

    @Autowired
    private TemplateEngine templateEngine;

    /* *
     * @Author yyliu
     * @Description 通过模板返回信息
     * @Date 16:02 2018/9/17
     * @Param [templateName, params]
     * @return java.lang.String
     **/
    public String templateContent(String templateName, Map<String, Object> params) {
        Context context = new Context();
        context.clearVariables();
        if (CollectionUtils.isNotEmpty(params)) {
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                context.setVariable(entry.getKey(), entry.getValue());
            }
        }

        return templateEngine.process(templateName, context);
    }

}
